package com.tjtt.gwm.dao.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.lang.*;
import java.util.*;


import org.hibernate.Query;

import com.google.common.base.Objects;
import com.jcraft.jsch.Session;
import com.tjtt.gwm.bean.EPInStore;
import com.tjtt.gwm.bean.EquipmentParts;
import com.tjtt.gwm.dao.EquipmentPartsDao;
import com.tjtt.tdm.base.BaseHibernateDao;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.base.StringUtil;
import com.tjtt.tdm.flow.bean.FlowDetailed;
import com.tjtt.tdm.flow.bean.FlowTask;
import com.tjtt.tdm.flow.bean.FlowTaskInfo;
import com.tjtt.tdm.system.bean.Organization;
import com.tjtt.tdm.system.bean.Users;

public class EquipmentPartsDaoImpl extends BaseHibernateDao implements EquipmentPartsDao {


	@Override
	public PageResult queryDataList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from TDM_EQUIPMENT_PARTS ep , gwm_gongyingshang g, sys_organization org  where g.id=ep.ep_supplier  and org.org_id=ep.ep_storehouse");
		StringBuffer queryString = new StringBuffer();	
		//queryString.append("select ep.id, org.org_name as ep_storehouse,ep.ep_code, ep.ep_name,ep.ep_property, ep.ep_level,ep.ep_guige, ep.ep_brand,g.gongyingshangname as ep_supplier,ep.EP_AVERAGEPRICE,ep.EP_CYCLE,ep.EP_MAXSTOCK,ep.EP_MINSTOCK," +
		//		"ep.EP_ACTUALSTOCK,ep.EP_STOCKSTATE,ep.EP_MEASUREMENTUNIT,t.equ_name as EP_APPLICABLEEQUIPMENT,t.equ_no as EP_APPLICABLEEQUIPMENTID ,ep.EP_STORAGELOCATION, ep.ep_remark" +
		//		" from TDM_EQUIPMENT_PARTS ep, gwm_gongyingshang g, tdm_equipment t, sys_organization org  where g.id=ep.ep_supplier and t.id=ep.ep_applicableequipment and org.org_id=ep.ep_storehouse");
		
		queryString.append("select ep.id, org.org_name as ep_storehouse,ep.ep_code, ep.ep_name,ep.ep_property, ep.ep_level,ep.ep_guige, ep.ep_brand,g.gongyingshangname as ep_supplier,ep.EP_AVERAGEPRICE,ep.EP_CYCLE,ep.EP_MAXSTOCK,ep.EP_MINSTOCK," +
				"ep.EP_ACTUALSTOCK,ep.EP_STOCKSTATE,ep.EP_MEASUREMENTUNIT,ep.EP_STORAGELOCATION, ep.ep_remark" +
				" from TDM_EQUIPMENT_PARTS ep, gwm_gongyingshang g, sys_organization org  where g.id=ep.ep_supplier  and org.org_id=ep.ep_storehouse");
		
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("epName") && !"".equals(filterMap.get("epName"))){
				queryString.append(" and ep.EP_NAME like '%"+filterMap.get("epName")+"%'");
				countString.append(" and ep.EP_NAME like '%"+filterMap.get("epName")+"%'");
			}
			if(null!=filterMap.get("epCode") && !"".equals(filterMap.get("epCode"))){
				queryString.append(" and ep.EP_CODE like '%"+filterMap.get("epCode")+"%'");
				countString.append(" and ep.EP_CODE like '%"+filterMap.get("epCode")+"%'");
			}
			if(null!=filterMap.get("choose") && !"".equals(filterMap.get("choose"))){
				queryString.append(" and ep.EP_ACTUALSTOCK<=ep.EP_MINSTOCK and ep.EP_STOCKSTATE='是'  ");
				countString.append(" and ep.EP_ACTUALSTOCK<=ep.EP_MINSTOCK and ep.EP_STOCKSTATE='是' ");
			}
			//国伟添加
			if(null!=filterMap.get("ids") && !"".equals(filterMap.get("ids"))){
				queryString.append(" and ep.id in ("+filterMap.get("ids")+")");
				countString.append(" and ep.id in ("+filterMap.get("ids")+")");
			}	
		}
		queryString.append(" and ep.EP_ISKY='0' order by ep.EP_CODE desc");
		countString.append(" and ep.EP_ISKY='0'");

		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	
	public PageResult queryCGDataList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from TDM_EQUIPMENT_PARTS ep where ep.EP_ACTUALSTOCK<=ep.EP_MINSTOCK and ep.EP_STOCKSTATE='是'");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select * from TDM_EQUIPMENT_PARTS ep  where ep.EP_ACTUALSTOCK<=ep.EP_MINSTOCK and ep.EP_STOCKSTATE='是'");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("epName") && !"".equals(filterMap.get("epName"))){
				queryString.append(" and ep.EP_NAME like '%"+filterMap.get("epName")+"%'");
				countString.append(" and ep.EP_NAME like '%"+filterMap.get("epName")+"%'");
			}
			if(null!=filterMap.get("epCode") && !"".equals(filterMap.get("epCode"))){
				queryString.append(" and ep.EP_CODE like '%"+filterMap.get("epCode")+"%'");
				countString.append(" and ep.EP_CODE like '%"+filterMap.get("epCode")+"%'");
			}		
		}
		queryString.append(" order by ep.EP_CODE desc");

		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	//获得最大的备件id
	public String queryMaxEPNo(){
		String no;
		String queryString="select Max(ep.ID) from TDM_EQUIPMENT_PARTS ep";
		List l=new ArrayList();
		Query query = getSession().createSQLQuery(queryString);
		l=query.list();
		if(l.size()==0){
			no="0";
		}
		else{
		  no=l.get(0).toString();
		}
		return no;
	}
	//依据备件id查询原数据（供应商、设备和部门已id形式存储）
	public EquipmentParts queryEPYuanListById(String id){
		BigDecimal ID=new BigDecimal(id);
		return this.getHibernateTemplate().get(EquipmentParts.class, ID);
	}
	//依据备件id查询备件详情
	public EquipmentParts queryDataById(String id){
		BigDecimal ID=new BigDecimal(id);
		EquipmentParts ep=new EquipmentParts();
		String sqlString="select ep.id, org.org_name as ep_storehouse,ep.ep_code, ep.ep_name,ep.ep_property, ep.ep_level,ep.ep_guige, ep.ep_brand,g.gongyingshangname as ep_supplier,ep.EP_AVERAGEPRICE,ep.EP_CYCLE,ep.EP_MAXSTOCK,ep.EP_MINSTOCK," +
		"ep.EP_ACTUALSTOCK,ep.EP_STOCKSTATE,ep.EP_MEASUREMENTUNIT, EP_APPLICABLEEQUIPMENT, EP_APPLICABLEEQUIPMENTID ,ep.EP_STORAGELOCATION, ep.ep_remark,ep.ep_isky" +
		" from TDM_EQUIPMENT_PARTS ep, gwm_gongyingshang g, sys_organization org  where g.id=ep.ep_supplier  and org.org_id=ep.ep_storehouse and ep.id="+ID;
		Query query=getSession().createSQLQuery(sqlString);
		List<EquipmentParts> eplist=query.list();
		Iterator iter = eplist.iterator();
		while(iter.hasNext()){			
			Object[] b=(Object[])iter.next();
			BigDecimal Id=(BigDecimal)b[0];
			String epStorehouse=(String)b[1];
			String epCode=(String)b[2];
			String epName=(String)b[3];
			String epProperty=(String)b[4];
			String epLevel=(String)b[5];
			String epGuige=(String)b[6];
			String epBrand=(String)b[7];
			String epSupplier=(String)b[8];
			String epAverageprice=(String)b[9];
			String epCycle=(String)b[10];
			BigDecimal epMaxstock=(BigDecimal)b[11];
			BigDecimal epMinstock=(BigDecimal)b[12];
			BigDecimal epActualstock=(BigDecimal)b[13];
			String epStockstate=(String)b[14];
			String epMeasurementunit=(String)b[15];
			String epApplicableequipment=(String)b[16];
			String epApplicableequipmentid=(String)b[17];
			String epStoragelocation=(String)b[18];
			String epRemark=(String)b[19];
			String epIsky=(String)b[20];
            ep.setId(Id);
            ep.setEpStorehouse(epStorehouse);
            ep.setEpCode(epCode);
            ep.setEpName(epName);
            ep.setEpProperty(epProperty);
            ep.setEpLevel(epLevel);
            ep.setEpGuige(epGuige);
            ep.setEpBrand(epBrand);
            ep.setEpSupplier(epSupplier);
            ep.setEpAverageprice(epAverageprice);
            ep.setEpCycle(epCycle);
            ep.setEpMaxstock(epMaxstock);
            ep.setEpMinstock(epMinstock);
            ep.setEpActualstock(epActualstock);
            ep.setEpStockstate(epStockstate);
            ep.setEpMeasurementunit(epMeasurementunit);
            ep.setEpApplicableequipment(epApplicableequipment);
            ep.setEpApplicableequipmentid(epApplicableequipmentid);
            ep.setEpStoragelocation(epStoragelocation);
            ep.setEpRemark(epRemark);
            ep.setEpIsky(epIsky);
		}
	
		return  ep;
		//this.getHibernateTemplate().get(EquipmentParts.class, ID);
		
	}
	//根据备件id查询备件信息（其中仓库，供应商和备件以id形式存储）
	public EquipmentParts queryEPDataById(String id){
		BigDecimal ID=new BigDecimal(id);
		EquipmentParts ep=new EquipmentParts();
		String sqlString="select * from TDM_EQUIPMENT_PARTS ep where ep.id="+ID;
		Query query=getSession().createSQLQuery(sqlString);
		List<EquipmentParts> eplist=query.list();
		Iterator iter = eplist.iterator();
		while(iter.hasNext()){			
			Object[] b=(Object[])iter.next();
			BigDecimal Id=(BigDecimal)b[0];
			String epStorehouse=(String)b[1];
			String epCode=(String)b[2];
			String epName=(String)b[3];
			String epProperty=(String)b[4];
			String epLevel=(String)b[5];
			String epGuige=(String)b[6];
			String epBrand=(String)b[7];
			String epSupplier=(String)b[8];
			String epAverageprice=(String)b[9];
			String epCycle=(String)b[10];
			BigDecimal epMaxstock=(BigDecimal)b[11];
			BigDecimal epMinstock=(BigDecimal)b[12];
			BigDecimal epActualstock=(BigDecimal)b[13];
			String epStockstate=(String)b[14];
			String epMeasurementunit=(String)b[15];
			String epApplicableequipment=(String)b[16];
			String epApplicableequipmentid=(String)b[17];
			String epStoragelocation=(String)b[18];
			String epRemark=(String)b[19];
			String epIsky=(String)b[20];
            ep.setId(Id);
            ep.setEpStorehouse(epStorehouse);
            ep.setEpCode(epCode);
            ep.setEpName(epName);
            ep.setEpProperty(epProperty);
            ep.setEpLevel(epLevel);
            ep.setEpGuige(epGuige);
            ep.setEpBrand(epBrand);
            ep.setEpSupplier(epSupplier);
            ep.setEpAverageprice(epAverageprice);
            ep.setEpCycle(epCycle);
            ep.setEpMaxstock(epMaxstock);
            ep.setEpMinstock(epMinstock);
            ep.setEpActualstock(epActualstock);
            ep.setEpStockstate(epStockstate);
            ep.setEpMeasurementunit(epMeasurementunit);
            ep.setEpApplicableequipment(epApplicableequipment);
            ep.setEpApplicableequipmentid(epApplicableequipmentid);
            ep.setEpStoragelocation(epStoragelocation);
            ep.setEpRemark(epRemark);
            ep.setEpIsky(epIsky);
		}
		return  ep;		
	}
	
	public void addepInStore(EPInStore epis){
		this.getHibernateTemplate().save(epis);
	}
	public void addEquipmentParts(EquipmentParts ep){
		this.getHibernateTemplate().save(ep);
	}
	
	public PageResult queryEPDataListByids(Map filterMap){		
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from TDM_EPINSTORE ep where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select ep.id,ep.ep_id, org.org_name as ep_storehouse,ep.ep_code, ep.ep_name,ep.ep_property, ep.ep_level,ep.ep_guige, ep.ep_brand,g.gongyingshangname as ep_supplier,ep.EP_INSTOREPRICE,ep.EP_INCYCLE,ep.EP_MAXSTOCK,ep.EP_MINSTOCK, "+ 
				" ep.EP_ACTUALSTOCK,ep.EP_INSTORENUM,ep.EP_INSTOREMONEY,ep.EP_INACTUALNUM,ep.EP_MEASUREMENTUNIT, EP_APPLICABLEEQUIPMENT, EP_APPLICABLEEQUIPMENTID,ep.EP_STORAGELOCATION, ep.ep_remark "+
				" from TDM_EPINSTORE ep , gwm_gongyingshang g, sys_organization org  where g.id=ep.ep_supplier and org.org_id=ep.ep_storehouse");
		
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("epInstoreno") && !"".equals(filterMap.get("epInstoreno"))){
				queryString.append(" and ep.ep_Instoreno="+"'"+filterMap.get("epInstoreno").toString()+"'");
				countString.append(" and ep.ep_Instoreno="+"'"+filterMap.get("epInstoreno").toString()+"'");
			}
			
		}
		queryString.append(" order by ep.EP_CODE desc");

		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	 //根据备件id查询入库单备件信息
	 public EPInStore queryEPInStoreByMainId(String mainid){
		int id=Integer.parseInt(mainid);
		return this.getHibernateTemplate().get(EPInStore.class, id);
	}
	 //根据备件id查询入库单备件信息
	 public EPInStore queryEPINfoByEPIdAndNo(String ids){
		 EPInStore ep=new EPInStore();
		 String queryString="  select ep.EP_INSTORENO,ep.EP_INSTOREDATE,ep.EP_INSTORETYPE,ep.EP_INSQDEP,ep.EP_INSQR, ep.id,ep.ep_id, org.org_name as ep_storehouse,ep.ep_code, ep.ep_name,ep.ep_property, ep.ep_level,ep.ep_guige, ep.ep_brand,g.gongyingshangname as ep_supplier,ep.EP_MAXSTOCK,ep.EP_MINSTOCK,"+  
				" ep.EP_ACTUALSTOCK,ep.EP_MEASUREMENTUNIT,EP_APPLICABLEEQUIPMENT, EP_APPLICABLEEQUIPMENTID,ep.EP_STORAGELOCATION,ep.EP_INSTORENUM,ep.EP_INSTOREPRICE, ep.EP_INSTOREMONEY,ep.EP_INCYCLE,ep.EP_INSHR,ep.EP_INSHRQ,ep.EP_INACTUALNUM,ep.EP_FLOWSTATE,ep.ep_remark  "+
				"  from TDM_EPINSTORE ep , gwm_gongyingshang g, sys_organization org  where g.id=ep.ep_supplier and org.org_id=ep.ep_storehouse and ep.ID="+ids;
		 List<EPInStore> l=new ArrayList();
		 Query query = getSession().createSQLQuery(queryString); 
		 l=query.list();
		 Iterator iter = l.iterator();
 		while(iter.hasNext()){
 			Object[] b=(Object[])iter.next();
 			String epInstoreno=(String)b[0];
 			String epInstoredate=(String)b[1];
 			String epInstoretype=(String)b[2];
 			String epInsqdep=(String)b[3];
 			String epInsqr=(String)b[4];
 			BigDecimal id1=(BigDecimal)b[5];
 			int id=id1.intValue();
 			String epId=(String)b[6];
 			String epStorehouse=(String)b[7];
 			String epCode=(String)b[8];
 			String epName=(String)b[9];
 			String epProperty=(String)b[10];
 			String epLevel=(String)b[11];
 			String epGuige=(String)b[12];
 			String epBrand=(String)b[13];
 			String epSupplier=(String)b[14];
 			BigDecimal epMaxstock1=(BigDecimal)b[15];
 			int epMaxstock=epMaxstock1.intValue();
 			BigDecimal epMinstock1=(BigDecimal)b[16];
 			int epMinstock=epMinstock1.intValue();
 			BigDecimal epActualstock1=(BigDecimal)b[17];
 			int epActualstock=epActualstock1.intValue();			
 			String epMeasurementunit=(String)b[18];
 			String epApplicableequipment=(String)b[19];
 			String epApplicableequipmentid=(String)b[20];
 			String epStoragelocation=(String)b[21];
 			BigDecimal epInstorenum1=(BigDecimal)b[22];
 			int epInstorenum=epInstorenum1.intValue();
 			BigDecimal epInstoreprice1=(BigDecimal)b[23];
 			double epInstoreprice=epInstoreprice1.doubleValue();
 			BigDecimal epInstoremoney1=(BigDecimal)b[24];
 			double epInstoremoney=epInstoremoney1.doubleValue();
 			String epIncycle=(String)b[25];
 			String epInshr = (String)b[26];
 			String epInshrq = (String)b[27];
 			BigDecimal epInactualnum1=(BigDecimal)b[28];
 			int epInactualnum=epInactualnum1.intValue();
 			String epFlowstate=(String)b[19];
 			String epRemark=(String)b[30];
 			ep.setEpInstoreno(epInstoreno);
 			ep.setEpInstoredate(epInstoredate);
 			ep.setEpInstoretype(epInstoretype);
 			ep.setEpInsqdep(epInsqdep);
 			ep.setEpInsqr(epInsqr);		
             ep.setId(id);
             ep.setEpId(epId);
             ep.setEpStorehouse(epStorehouse);
             ep.setEpCode(epCode);
             ep.setEpName(epName);
             ep.setEpProperty(epProperty);
             ep.setEpLevel(epLevel);
             ep.setEpGuige(epGuige);
             ep.setEpBrand(epBrand);
             ep.setEpSupplier(epSupplier);
             ep.setEpMaxstock(epMaxstock);
             ep.setEpMinstock(epMinstock);
             ep.setEpActualstock(epActualstock);
             ep.setEpMeasurementunit(epMeasurementunit);
             ep.setEpApplicableequipment(epApplicableequipment);
             ep.setEpApplicableequipmentid(epApplicableequipmentid);
             ep.setEpStoragelocation(epStoragelocation);
             ep.setEpInstorenum(epInstorenum);
             ep.setEpInstoreprice(epInstoreprice);
             ep.setEpInstoremoney(epInstoremoney);
             ep.setEpIncycle(epIncycle);
             ep.setEpInactualnum(epInactualnum);
             ep.setEpInshr(epInshr);
             ep.setEpInshrq(epInshrq);
             ep.setEpFlowstate(epFlowstate);
             ep.setEpRemark(epRemark);
             ep.setEpRemark(epRemark);
 		} 
 		return ep;
	 }
	//根据入库单号查询入库单信息
	 public List<EPInStore>  queryEPINfoByEPInNo(String instoreNo){
		 String queryString="";
		 if(instoreNo==null||instoreNo.equals("")){
			 queryString="select * from TDM_EPINSTORE epis where epis.EP_INSQR is null";
		 }
		 else{
			 queryString="select * from TDM_EPINSTORE epis where epis.EP_INSTORENO="+"'"+instoreNo+"'";
		 }
		 List<EPInStore> l=new ArrayList();
		 Query query = getSession().createSQLQuery(queryString);
		 l=query.list();
		// if(l.size()>0&&l!=null){
			 System.out.println("-----l---------"+l.size()+"--------------"+l);
		     return l;
		
		 
	 }
	 public EPInStore  queryEPINfoByEPId(String id){
		int ID=Integer.parseInt(id);
		return this.getHibernateTemplate().get(EPInStore.class, ID);
	 }
	//根据入库单号更新入库单信息
	 public void updateEPINfoByEPIdAndNo(EPInStore epis){
		 this.getHibernateTemplate().update(epis);
	 }
	//更新备件台账信息
	 public void updateEquipmentParts(EquipmentParts ep){		 
		 this.getHibernateTemplate().update(ep);
	 }
	 	 
	 
	//获得最大的入库单号
	public String queryMaxRKNo(){
		String no;
		String queryString="select Max(epis.EP_INSTORENO) from TDM_EPINSTORE epis";
		List l=new ArrayList();
		Query query = getSession().createSQLQuery(queryString);
		l=query.list();
		Object maxNo=l.get(0);
		if(maxNo==null){
			no="";
		}
		else{
		  no=l.get(0).toString();
		}
		return no;
	}
	
	//删除冗余数据
	public void deleteEPInData(EPInStore ep){
		this.getHibernateTemplate().delete(ep);
	}
	//根据用户id查询用户姓名
	public Users queryUsersName(String id ){
		Long ID=Long.parseLong(id);
		return this.getHibernateTemplate().get(Users.class,ID);
	}
	//根据部门id查询部门名称
	public  Organization queryOrganizationName(String orgId){
		Long ID=Long.parseLong(orgId);
		return this.getHibernateTemplate().get(Organization.class, ID);
		
	}
	
	
	//查询设备列表
	public PageResult queryEP(Map filterMap){
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from TDM_EQUIPMENT ep where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select ep.ID, ep.EQU_NAME ,ep.EQU_NO from TDM_EQUIPMENT ep where 1 = 1 ");
		
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("epName") && !"".equals(filterMap.get("epName"))){
				queryString.append(" and ep.EQU_NAME like '%"+filterMap.get("epName")+"%'");
				countString.append(" and ep.EQU_NAME like '%"+filterMap.get("epName")+"%'");
			}
			if(null!=filterMap.get("epNo") && !"".equals(filterMap.get("epNo"))){
				queryString.append(" and ep.EQU_NO like '%"+filterMap.get("epNo")+"%'");
				countString.append(" and ep.EQU_NO like '%"+filterMap.get("epNo")+"%'");
			}
		}
		queryString.append(" order by ep.ID desc");

		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	//查询供应商列表
	public PageResult queryGYS(Map filterMap){
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from GWM_GONGYINGSHANG ep where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select ep.ID, ep.GONGYINGSHANGNAME as GYS_NAME ,ep.GONGYINGSHANGDIZHI as GYS_DIZHI from GWM_GONGYINGSHANG ep where 1 = 1 ");
		
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("gysName") && !"".equals(filterMap.get("gysName"))){
				queryString.append(" and ep.GONGYINGSHANGNAME like '%"+filterMap.get("gysName")+"%'");
				countString.append(" and ep.GONGYINGSHANGNAME like '%"+filterMap.get("gysName")+"%'");
			}
			
		}
		queryString.append(" order by ep.ID desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public PageResult queryEquRelationByID(Map filterMap){
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from FORMRELATEEQU ep ");
		StringBuffer queryString = new StringBuffer();	
		//queryString.append("select ep.ids,ep.epcode,ep.epname,ep.epguige,ep.epaverageprice,ep.outnum from FORMRELATEEQU ep");
		queryString.append("select ep.equid,ep.epcode,ep.epname,ep.epguige,ep.epaverageprice,ep.outnum from FORMRELATEEQU ep");
		queryString.append("  where ep.formid = "+filterMap.get("ids"));
		countString.append("  where ep.formid = "+filterMap.get("ids"));
				
	    return searchBySQL(countString.toString(),queryString.toString(),filterMap);		
	}
	/*
	 * 根据表名和对象id获取flowtaskId
	 * wy
	 */
	public List getFlowtaskId(String tablename,String mainid){
		String sql = "select t.id from FLOW_TASK t where t.table_name='"+tablename+"' and t.main_id='"+mainid+"'";
		Query query = getSession().createSQLQuery(sql);
		List list = query.list();
		return list;
	}
	
	/*
	 * 获取FlowTaskInfo对象
	 * wy
	 */
	public FlowTaskInfo getFlowTaskInfo(String flowTaskId){
		String sql = "select t.id from FLOW_TASK_INFO t where t.flow_task_id="+flowTaskId;
		Query query = getSession().createSQLQuery(sql);
		List list = query.list();
		if(null != list && list.size()>0){
			String flowtaskinfoId = list.get(0).toString();
			return this.getHibernateTemplate().get(FlowTaskInfo.class, Long.parseLong(flowtaskinfoId));
		}else{
			return null;
		}
		
	}
	/*
	 * 获取FlowDetailed对象
	 * wy
	 */
	public FlowDetailed getFlowDetailed(String flowTaskId){
		String sql = "select t.id from FLOW_DETAILED t where t.flow_task_id="+flowTaskId;
		Query query = getSession().createSQLQuery(sql);
		List list = query.list();
		if(null != list && list.size()>0){
			String id = list.get(0).toString();
			Long ID=Long.parseLong(id);
			return this.getHibernateTemplate().get(FlowDetailed.class, ID);
		}else{
			return null;
		}
		
	}
	//更新FlowDetailed对象
	public void updateFlowDetailed(FlowDetailed f){
		this.getHibernateTemplate().update(f);
	}
	/*
	 * 保存FlowTaskInfo对象
	 * wy
	 */
	public void updateFlowTaskInfo(FlowTaskInfo flowTaskInfo){
		this.getHibernateTemplate().update(flowTaskInfo);
	}
	//获取flowtask对象
	public FlowTask getFlowTask(String id){
		Long ID= Long.parseLong(id);
		return this.getHibernateTemplate().get(FlowTask.class, ID);	
	}
	//更新flowtask对象
	public void updateFlowTask(FlowTask f){
		this.getHibernateTemplate().update(f);
	}
	// 根据sql语句查询数据
	public List queryDataBySql(String sql){
		Query query = getSession().createSQLQuery(sql);
  	    List list = query.list();
  	    return list;
	}

}
